package com.moshme.web.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.moshme.common.core.controller.BaseController;
import com.moshme.common.core.domain.AjaxResult;
import com.moshme.project.domain.StageCheckFile;
import com.moshme.project.domain.StageProgramme;
import com.moshme.project.service.StageCheckFileService;
import com.moshme.project.service.StageProgrammeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Kieyfr
 * @version 1.0
 * @description 方案阶段接口
 * @date 2023/8/29 10:21
 */
@RestController
@RequestMapping("stageProgramme")
@Api("方案阶段")
public class StageProgrammeController extends BaseController {
    @Autowired
    private StageProgrammeService stageProgrammeService;

    /**
     * 方案阶段获取文件
     *
     * @param projectId
     * @return
     */
    @GetMapping
    @ApiOperation(value = "方案阶段获取文件")
    public AjaxResult getStageCheckFile(Long projectId){
        LambdaQueryWrapper<StageProgramme> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        StageProgramme stageProgramme = stageProgrammeService.getOne(lambdaQueryWrapper.eq(StageProgramme::getProjectId, projectId));
        if (stageProgramme==null){
            return error("方案阶段中没有文件");
        }
        return success(stageProgramme);
    }

    /**
     * 上传文件
     *
     * @param file
     * @param projectId
     * @return
     */
    @PostMapping("upload")
    @ApiOperation(value = "方案阶段上传文件")
    public AjaxResult upload(MultipartFile file, Long projectId){
        String filePath = stageProgrammeService.upload(file, projectId);
        return success(filePath);
    }

    /**
     * 删除文件
     *
     * @param projectId
     * @return
     */
    @DeleteMapping("delFile")
    @ApiOperation(value = "方案阶段删除文件")
    public AjaxResult delFile(Long projectId){
        if (stageProgrammeService.delFile(projectId)){
            return success("删除成功");
        }
        return error("删除失败");
    }

}
